// packageA/pages/liao/liao.js
const recorderManager = wx.getRecorderManager()
const innerAudioContext = wx.createInnerAudioContext()
const app = getApp()
const {
  forEach
} = require("jszip");
const zim = app.globalData.zim;
// 设置日志显示
zim.setLogConfig({
  logLevel: 'error'
})
const INTERVAL = 5000;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    appurl: app.apiurl,
    apiimg: app.apiimg,
    items: [
      '没完成游戏',
      '游戏等级错误',
      '性别错误',
      '虚假主页内容',
      '消极游戏',
      '侮辱谩骂'
    ],
    lh_reasion_id: "",
    yaoqing1: false,
    yaoqing2: false,
    toView: '',
    tmp_url: '',
    checkStatus: 0,
    send_type: '1',
    yuyin1: false,
    luyin1: false,
    luyin2: true,
    luyin3: false,
    luyin4: false,
    status: 1,
    sp_ren_img1: false,
    jinbi_num: 0,
    nums: 0,
    dashangtc: false,
    zhuyetc: false,
    zhuyetc1: false,
    xinrenyindao1: false,
    xinrenyindao2: false,
    xinrenyindao3: false,
    dashangflag: false,
    msg:''
  },
  z_datu(e) {
    let _this = this
    _this.setData({
      sp_ren_img1: true,
      datu: e.currentTarget.dataset.id
    })
  },
  close1() {
    this.setData({
      sp_ren_img1: false
    })
  },
  yuyin() {
    let _this = this
    _this.setData({
      yuyin1: !_this.data.yuyin1
    })
  },
  z_luyin1() {
    let _this = this
    if (_this.data.status == 1) {
      wx.authorize({
        scope: "scope.record",
        success() {
          console.log("录音授权成功");
          //第一次成功授权后 状态切换为2
          _this.setData({
            status: 2,
            luyin2: false,
            luyin3: true
          })
        },
      })
    } else {
      _this.setData({
        luyin1: true
      })
    }
  },
  //发送语音
  touchstart() {
    var that = this
    const options = {
      duration: 60000, //指定录音的时长，单位 ms
      sampleRate: 16000, //采样率
      numberOfChannels: 1, //录音通道数
      encodeBitRate: 96000, //编码码率
      format: "wav", //音频格式，有效值 aac/mp3
      frameSize: 50, //指定帧大小，单位 KB
    }
    //开始录音
    wx.authorize({
      scope: "scope.record",
      success() {
        console.log("录音授权成功");
        //第一次成功授权后 状态切换为2
        that.setData({
          status: 2,
          luyin1: true
        })
        recorderManager.start(options);
        recorderManager.onStart(() => {
          console.log("recorder start")
        });
        //错误回调
        recorderManager.onError((res) => {
          console.log(res);
        })
      },
      fail() {
        console.log("第一次录音授权失败");
        wx.showModal({
          title: "提示",
          content: "您未授权录音，功能将无法使用",
          showCancel: true,
          confirmText: "授权",
          confirmColor: "#52a2d8",
          success: function (res) {
            if (res.confirm) {
              //确认则打开设置页面（重点）
              wx.openSetting({
                success: (res) => {
                  console.log(res.authSetting);
                  if (!res.authSetting["scope.record"]) {
                    //未设置录音授权
                    console.log("未设置录音授权");
                    wx.showModal({
                      title: "提示",
                      content: "您未授权录音，功能将无法使用",
                      showCancel: false,
                      success: function (res) {

                      },
                    })
                  } else {
                    //第二次才成功授权
                    console.log("设置录音授权成功");
                    that.setData({
                      status: 2,
                    })

                    recorderManager.start(options);
                    recorderManager.onStart(() => {
                      console.log("recorder start")
                    });
                    //错误回调
                    recorderManager.onError((res) => {
                      console.log(res);
                    })
                  }
                },
                fail: function () {
                  console.log("授权设置录音失败");
                }
              })
            } else if (res.cancel) {
              console.log("cancel");
            }
          },
          fail: function () {
            console.log("openfail");
          }
        })
      }
    })
  },
  touchend() {
    let _this = this
    recorderManager.stop();
    recorderManager.onStop((res) => {
      console.log("录音：", res)
      _this.tempFilePath = res.tempFilePath
      _this.setData({
        // tempFilePath: res.tempFilePath,
        luyin1: false,
        luyin4: true
      })
      setTimeout(function () {
        _this.setData({
          luyin4: false
        })
      }, 2000)
      var tempFiles = res.tempFilePath;
      // var tempFiles = res.tempFiles[0]['tempFilePath'];
      // console.log("111111111111",tempFiles)
      wx.uploadFile({
        url: app.apiurl + 'api/common/upload',
        filePath: tempFiles,
        name: 'file',
        formData: {
          "token": wx.getStorageSync("user_token"),
          'api_type': 'file',
          'video_url': tempFiles
        },
        success(res) {
          const data = JSON.parse(res.data)
          console.log('sadasdasdssdf', data)
          _this.setData({
            msg: data.data.fullurl,
            send_type: '2'
          })
          _this.xiaoxi()
        }
      })
    })
    console.log("音频", _this.data.tempFilePath)

  },
  play(e) {
    // innerAudioContext.autoplay = true
    // innerAudioContext.src = e.currentTarget.dataset.id,
    //   innerAudioContext.onPlay(() => {
    //     console.log("开始播放")
    //   })
    // innerAudioContext.onError((res) => {
    //   console.log(res.errMsg)
    //   console.log(res.errCode)
    // })
    let _this = this
    _this.setData({
      audio_url1: e.currentTarget.dataset.content
    })
    _this.play1()
  },
  play2(e) {
    let _this = this
    let curMessageList = _this.data.curMessageList;
    curMessageList[e.currentTarget.dataset.index].state = '1';
    _this.setData({
      audio_url1: e.currentTarget.dataset.content,
      curMessageList: curMessageList
    })
    setTimeout(function () {
      _this.xiaoxi0925()
    }, 2000)
    _this.play1()
    let params = {
      "token": wx.getStorageSync("user_token"),
      "id": e.currentTarget.dataset.id,
      "other_member_id": _this.data.duifang.id
    }
    wx.request({
      url: app.apiurl + 'api/member/chatMsgIsRead',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        console.log(res.data.data)
        //  _this.guanggao2()
      }
    })
  },
  play1() {
    console.log(this.data.audio_url1)
    this.setData({
      muted1: false,
      autoplay1: true,
    })
    this.videoContext.play();
  },
  zz_zanting() {
    this.setData({
      muted1: true,
      autoplay1: false,
    })
    this.videoContext.pause();
  },
  //发送图片
  // upload() {
  //   let that = this
  //   wx.chooseMedia({
  //     count: 1,
  //     mediaType: ['image'],
  //     sourceType: ['album', 'camera'],
  //     maxDuration: 30,
  //     camera: 'back',
  //     success(e) {
  //       var tempFiles = e.tempFiles[0]['tempFilePath'];
  //       var fileSize = e.tempFiles[0]['size'];
  //       var MAX_SIZE = Number(that.data.peizhi.config_param39) * 1024 * 1024;
  //       if (fileSize > MAX_SIZE) {
  //         wx.showToast({
  //           title: '文件超过大小限制',
  //           icon: 'none',
  //         });
  //         // 文件超过限制，处理逻辑，比如重新选择
  //         return;
  //       } else {
  //         wx.uploadFile({
  //           url: app.apiurl + 'api/common/upload',
  //           filePath: tempFiles,
  //           name: 'file',
  //           formData: {},
  //           success(res) {
  //             const data = JSON.parse(res.data)
  //             that.setData({
  //               msg:data.data.fullurl,
  //               send_type:'3'
  //             })
  //             that.xiaoxi()
  //           }
  //         })
  //       }
  //     }
  //   })
  // },
  onChooseAvatar(e) {
    let that = this
    var tempFiles = e.detail.avatarUrl;
    wx.uploadFile({
      url: app.apiurl + 'api/common/upload',
      filePath: tempFiles,
      name: 'file',
      formData: {},
      success(res) {
        const data = JSON.parse(res.data)
        that.setData({
          msg: data.data.fullurl,
          send_type: '3'
        })
        that.xiaoxi()
      }
    })
  },
  upload() {
    let that = this
    wx.chooseImage({
      // 最多可以选择的图片张数
      count: 1,
      sizeType: ["compressed"],
      //   选择图片的来源
      sourceType: ["album", "camera"],
      success: function (res) {
        that.setData({
          temppath: res.tempFilePaths,
          fileSize: res.tempFiles[0]['size'],
          MAX_SIZE: Number(that.data.peizhi.config_param39) * 1024 * 1024
        })
        setTimeout(function () {
          that.z_shangchuan()
        }, 1000)
      },
    })
  },
  z_shangchuan() {
    let _this = this
    var temppath = _this.data.temppath;
    var fileSize = _this.data.fileSize;
    var MAX_SIZE = _this.data.MAX_SIZE;
    if (fileSize > MAX_SIZE) {
      wx.showToast({
        title: '文件超过大小限制',
        icon: 'none',
      });
      // 文件超过限制，处理逻辑，比如重新选择
      return;
    } else {
      wx.uploadFile({
        // 开发者服务器地址
        url: 'https://www.zonghengxin.com/api/common/upload',
        filePath: temppath[0],
        name: 'file',
        formData: {},
        // 超时时间，单位为毫秒
        timeout: 600000000,
        header: {
          "content-type": "multipart/form-data"
        },
        success(res) {
          const data = JSON.parse(res.data)
          _this.setData({
            msg: data.data.fullurl,
            send_type: '3'
          })
          _this.xiaoxi()
        },
        fail(aaa) {
          console.log('失败：', aaa)
        }
      })
    }
  },
  upload111() {
    let _this = this
    wx.chooseMedia({
      count: 1,
      mediaType: ['image'], // 只允许选择图片
      sourceType: ['album', 'camera'], // 可以拍摄或从相册中选择
      sizeType: ['compressed'], // 选择压缩图
      camera: 'back', // 后置摄像头
      success: (res) => {
        //读取文件
        const fs = wx.getFileSystemManager()
        const payload = fs.readFileSync(res.tempFiles[0]['tempFilePath'])
        console.log('11111111', payload)
        wx.request({
          url: res.upload_url,
          method: 'PUT',
          header: {
            'content-type': 'multipart/form-data; boundary=XXX'
          },
          data: payload,
          success: (rev) => {}
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let that = this
    that.setData({
      other_member_id: options.id,
      sy_id: options.sid,
    })

    wx.request({
      url: app.apiurl + 'api/home/xcxLoginStatus',
      method: 'GET',
      data: {},
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        if (res.data.code == '1001') {
          if (res.data.data.is_force_login == '1') {
            that.setData({
              dashangflag: true
            })
          }
        }
      }
    })


    this.timer = setInterval(function () {
      that.xiaoxi3()
      // 这里可以执行定时器需要执行的任务
    }, INTERVAL);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.videoContext = wx.createVideoContext('myVideo');
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.autoScroll()
    this.z_peizhi()
    this.z_duifang()
    this.z_yonghu()
    this.xiaoxi2()
    this.z_laheiyy()
    this.z_xianhua()

    if (wx.getStorageSync("user_token") != "") {
      this.z_xinrenyindao()
    }

    let _this = this
    setTimeout(function () {
      _this.z_yaoqing()
      _this.z_chuci()
    }, 500)
  },
  z_chuci() {
    let _this = this;
    let myArray = [];
    let targetNumber = _this.data.duifang.id;
    let isExist = false;
    if (wx.getStorageSync("myArrayKey") != '') {
      myArray = JSON.parse(wx.getStorageSync("myArrayKey"));
    }
    for (let i = 0; i < myArray.length; i++) {
      if (myArray[i] === targetNumber) {
        isExist = true;
        break;
      }
    }
    if (!isExist && _this.data.sy_id == 999) {
      _this.setData({
        yaoqing2: true
      })
      myArray.push(targetNumber);
      wx.setStorageSync("myArrayKey", JSON.stringify(myArray));
      if (_this.data.zhuyetc) {
        _this.setData({
          zhuyetc: false,
          zhuyetc1: true
        })
      }
    }
  },
  z_xinrenyindao() {
    if (wx.getStorageSync("xinrenyindao1") == '') {
      this.setData({
        xinrenyindao1: true,
        xinrenyindao2: false,
      })
    } else if (wx.getStorageSync("xinrenyindao1") == '1') {
      this.setData({
        xinrenyindao1: false,
        xinrenyindao2: true,
      })
    } else if (wx.getStorageSync("xinrenyindao1") == '2') {
      this.setData({
        xinrenyindao1: false,
        xinrenyindao2: false,
      })
    }
  },
  z_xinrenyindao1() {
    wx.setStorageSync("xinrenyindao1", '1')
    this.z_xinrenyindao()
  },
  z_xinrenyindao2() {
    wx.setStorageSync("xinrenyindao1", '2')
    this.setData({
      xinrenyindao2: false
    })
    this.z_xinrenyindao()
  },
  z_xianhua() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/xianhuaList',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          navlist3: res.data.data
        })
      }
    })
  },
  z_yonghu() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/myInfo',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        if (res.data.code == '1001') {
          _this.setData({
            yonghu: res.data.data,
            jg_token: res.data.data.jg_token,
            jg_member_id: res.data.data.jg_member_id
          })
        }
      }
    })
  },
  //对方资料
  z_duifang() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/member/otherMemberInfo?other_member_id=' + _this.data.other_member_id,
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          duifang: res.data.data
        })
        if (res.data.data.homeInfo != '' && res.data.data.homeInfo != null && wx.getStorageSync("zhuye_home") != new Date().getDate()) {
          _this.setData({
            zhuyetc: true
          })
        }
      }
    })
  },
  z_peizhi() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/configBase',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        console.log(res.data.data)
        _this.setData({
          peizhi: res.data.data
        })
      }
    })
  },
  z_yaoqing() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
      "other_member_id": _this.data.other_member_id,
    }
    wx.request({
      url: app.apiurl + 'api/compete/checkYqMember',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          checkStatus: res.data.data.checkStatus
        })
        let time = _this.data.peizhi.config_param25;
        time = Number(time) * 60 * 1000;
        setTimeout(function () {
          _this.setData({
            checkStatus: '1'
          })
        }, time)
      }
    })
  },
  z_laheiyy() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
    }
    wx.request({
      url: app.apiurl + 'api/config/lhReasonList',
      method: 'GET',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          items: res.data.data
        })
      }
    })
  },
  autoScroll() {
    let _this = this
    _this.setData({
      toView: "toView"
    })
    console.log("到最底部", _this.data.toView)
  },
  //即构登录
  jg_login() {
    let _this = this
    let userInfo = {
      userID: "user_" + _this.data.jg_member_id,
      userName: _this.data.yonghu.name
    };
    let token = _this.data.jg_token;

    zim.login(userInfo, token)
      .then(function () {
        console.log("登录成功")
        setTimeout(function () {
          _this.chuangjian()
        }, 1500)
      })
      .catch(function (err) {
        console.log("登录失败", err)
      });
  },
  chuangjian() {
    let _this = this

    // 获取单聊会话历史消息
    var curMessageList = [];

    var conversationID = 'member_' + _this.data.duifang.id;
    var conversationType = 0;
    // 从后往前获取会话历史消息，每次获取 30 条
    var config = {
      nextMessage: null, // 首次获取时 nextMessage 为 null
      count: 30,
      reverse: true
    }

    function queryMessageCallback({
      messageList
    }) {
      curMessageList.push(...messageList);

      // 手指往下滑动到屏幕最上方一条消息时，获取更早的消息
      if (fetchMore && messageList.length > 0) {
        // 后续分页获取时，nextMessage 为当前获取到的消息列表的第一条消息
        config.nextMessage = messageList[0];
        zim.queryHistoryMessage(conversationID, conversationType, config).then(queryMessageCallback);
      }
    }

    zim.queryHistoryMessage(conversationID, conversationType, config).then(queryMessageCallback);
  },
  //     xiaoxi(){
  //       let _this = this
  //       // 发送单聊 `Text` 信息

  // var toConversationID = 'member_' + _this.data.duifang.id; // 对方 userID
  // var conversationType = 0; // 会话类型，取值为 单聊：0，房间：1，群组：2
  // var config = { 
  //     priority: 1, // 设置消息优先级，取值为 低：1（默认），中:2，高：3
  // };

  // var messageTextObj = { type: 1, message: _this.data.msg, extendedData: '消息的扩展信息（可选）' };
  // var notification = {
  //     onMessageAttached: function(message) {
  //         // todo: Loading
  //     }
  // }

  // zim.sendMessage(messageTextObj, toConversationID, conversationType, config, notification)
  //     .then(function ({ message }) {
  //         // 发送成功
  //         _this.chuangjian()
  //         _this.setData({
  //           msg: ""
  //         })
  //     })
  //     .catch(function (err) {
  //         // 发送失败
  //     });
  //     },
  xiaoxi11() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
      "content": _this.data.msg,
    }
    wx.request({
      url: app.apiurl + 'api/member/checkmsg',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          msg: res.data.data.content,
          tmp_url: res.data.data.tmp_url
        })
        _this.xiaoxi()
      }
    })
  },
  xiaoxi() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
      "other_member_id": _this.data.other_member_id,
      "content": _this.data.msg,
      "tmp_url": _this.data.tmp_url,
      "send_type": _this.data.send_type
    }
    wx.request({
      url: app.apiurl + 'api/member/chatSendMsg',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          msg: '',
          tmp_url: ''
        })
        _this.xiaoxi2()
      }
    })
  },
  xiaoxi1(e) {
    let _this = this
    _this.setData({
      msg: e.detail.value,
      xiaoxitype: 1,
      send_type: '1'
    })
  },
  xiaoxi2() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
      "page_no": "1",
      "page_num": "500",
      "cur_max_id": '0',
      "other_member_id": _this.data.other_member_id,
    }
    wx.request({
      url: app.apiurl + 'api/member/chatRecordList',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        console.log('11111', res.data.data.list)
        _this.setData({
          curMessageList: res.data.data.list
        })
        _this.z_duifang()
        _this.z_yonghu()
        _this.autoScroll()
      }
    })
  },
  xiaoxi0925() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
      "page_no": "1",
      "page_num": "500",
      "cur_max_id": '0',
      "other_member_id": _this.data.other_member_id,
    }
    wx.request({
      url: app.apiurl + 'api/member/chatRecordList',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.setData({
          curMessageList: res.data.data.list
        })
      }
    })
  },
  xiaoxi3() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
      "other_member_id": _this.data.duifang.id,
    }
    wx.request({
      url: app.apiurl + 'api/member/chatNewMessInfo',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        if (res.data.data.total != 0) {
          // let curMessageList = _this.data.curMessageList
          // for(let i=0;i<res.data.data.list.length;i++){
          //   curMessageList.push(res.data.data.list[i])
          //   console.log('111111111',i)
          // }
          // _this.setData({
          //   curMessageList:curMessageList
          // })
          // _this.autoScroll()
          _this.xiaoxi2()
        }
      }
    })
  },
  back() {
    wx.navigateBack({
      delta: 0,
    })
  },
  fuzhi1(e) {
    let text = e.currentTarget.dataset.text;
    let _this = this
    wx.setClipboardData({
      data: text,
      success(res) {
        wx.getClipboardData({
          success(res) {
            console.log(res.data) // data
            // wx.showToast({
            //   title: '复制成功',
            //   icon: 'success',
            //   duration: 2000
            // })
          }
        })
      }
    })
  },
  haoping1() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
      "other_member_id": _this.data.duifang.id,
    }
    wx.request({
      url: app.apiurl + 'api/member_kh/haoping',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.z_duifang()
      }
    })
  },
  shouchang1() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
      "other_member_id": _this.data.duifang.id,
      "state": '1',
      "is_ts": '0'
    }
    wx.request({
      url: app.apiurl + 'api/member/memberScAdd',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.z_duifang()
      }
    })
  },
  // shouchang2(){
  //   wx.navigateTo({
  //     url: '/packageA/pages/my_shouchang/my_shouchang',
  //   })
  // },
  shouchang2() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
      "other_member_id": _this.data.duifang.id,
      "state": '0',
      "is_ts": '0'
    }
    wx.request({
      url: app.apiurl + 'api/member/memberScAdd',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.z_duifang()
      }
    })
  },
  radioChange(e) {
    console.log('radio发生change事件，携带value值为：', e.detail.value)
    const items = this.data.items
    for (let i = 0, len = items.length; i < len; ++i) {
      items[i].checked = items[i].value === e.detail.value
    }
    this.setData({
      lh_reasion_id: e.detail.value
    })
  },
  lahei1() {
    this.setData({
      lahei: true
    })
  },
  lahei2() {
    this.setData({
      lahei: false
    })
  },
  lahei3() {
    let _this = this
    if (_this.data.lh_reasion_id == '') {
      wx.showToast({
        title: '请选择拉黑原因',
        duration: 2000
      })
      return false;
    }
    _this.setData({
      u_lh_flag: "1",
      lahei: false
    })
    let params = {
      "token": wx.getStorageSync("user_token"),
      "other_member_id": _this.data.duifang.id,
      "type": 'add',
      "lahei_resaon": _this.data.lh_reasion_id
    }
    wx.request({
      url: app.apiurl + 'api/member/memberLahei',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        _this.z_duifang()
        // wx.reLaunch({
        //   url: '/packageA/pages/xiaoxi/xiaoxi',
        // })
        if(res.data.code == '1002'){
          wx.showToast({
            title: '每天只能拉黑' + _this.data.peizhi.config_param105 + '名会员',
            icon: 'none',
            duration: 2000
          })
        } 
      }
    })
  },
  yaoqing1() {
    this.setData({
      yaoqing1: true
    })
  },
  dashang1() {
    this.setData({
      yaoqing2: true
    })
  },
  z_close() {
    this.setData({
      yaoqing1: false,
      yaoqing2: false,
      zhuyetc: false
    })
  },
  z_close1() {
    this.setData({
      dashangtc: false
    })
  },
  z_close2() {
    this.setData({
      zhuyetc: false
    })
    wx.setStorageSync("zhuye_home", new Date().getDate())
  },
  z_close3() {
    this.setData({
      yaoqing2: false
    })
    if (this.data.zhuyetc1) {
      this.setData({
        zhuyetc: true
      })
    }
  },
  z_shaixuan4(e) {
    let _this = this
    _this.setData({
      type2: e.currentTarget.dataset.index,
      idx: _this.data.navlist3[e.currentTarget.dataset.index].id,
      jinbi_num: e.currentTarget.dataset.jinbi_num,
      nums: e.currentTarget.dataset.nums
    })
  },
  yaoqing2() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
      "other_member_id": _this.data.duifang.id,
      "xh_id": _this.data.idx,
    }
    wx.request({
      url: app.apiurl + 'api/compete/yqkhBm',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        wx.showToast({
          title: res.data.msg,
          icon: 'none',
          duration: 2000
        })
        _this.z_close()
        _this.z_yaoqing()

      }
    })
  },
  dashang2() {
    let _this = this
    let params = {
      "token": wx.getStorageSync("user_token"),
      "other_member_id": _this.data.duifang.id,
      "xh_id": _this.data.idx,
    }
    wx.request({
      url: app.apiurl + 'api/member/dashangXh',
      method: 'POST',
      data: params,
      header: {
        'content-type': 'application/x-www-form-urlencoded' // 修改请求
      },
      success(res) {
        if (res.data.code == '1001') {
          _this.setData({
            dashangtc: true
          })
          _this.z_close()
          _this.z_yaoqing()
        } else {
          wx.showToast({
            title: res.data.msg,
            icon: 'none',
            duration: 2000
          })
        }

      }
    })
  },
  zhuye2() {
    wx.showToast({
      title: '该会员没有发布主页',
      icon: 'none',
      duration: 2000
    })
  },
  zhuye3() {
    let that = this;
    wx.navigateTo({
      url: '/packageA/pages/home_list/home_list?id=' + that.data.duifang.id + '&title=' + that.data.duifang.name
    })

  },
  // z_url(e){
  //   let link = encodeURIComponent(e.currentTarget.dataset.link);
  //   link = decodeURIComponent(link);
  //   wx.setStorage({
  //     key: "userInfo",
  //     data: { link: link}
  //   })
  //   wx.navigateTo({
  //     url: '/packageB/pages/danye/danye',
  //   })
  // },
  z_url(e) {
    let _this = this
    wx.setClipboardData({
      data: e.currentTarget.dataset.link,
      success(res) {
        wx.getClipboardData({
          success(res) {
            console.log(res.data) // data
            wx.showToast({
              title: '复制成功，请在浏览器粘贴',
              icon: 'none',
              duration: 2000
            })
          }
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    // if (this.timer) {
    //   clearInterval(this.timer);
    // }
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    if (this.timer) {
      clearInterval(this.timer);
    }
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})